$(function () {
    $('form').validate({
        rules: {
            user: {
                required: true,
                isUser: true
            },
            pwd: {
                required: true,
                isPwd: true
            },
            checkPwd:{
                equalTo:'#pwd'
            },
            phone:{
                required: true,
                isPhone: true
            },
        },





        
        messages: {
            user: {
                required: '必须输入用户名'
               
            },
            pwd: {
                required: '必须输入密码'

            },
            checkPwd:{
                equalTo:'两次密码不一致'
            },
            phone:{
                required: '请输入电话号码'
            },

        }
    });

    // 自定义用户验证
    jQuery.validator.addMethod('isUser', function (value, element) {
        var tel = /^[a-zA-Z]\w{5,11}$/;
        return this.optional(element) || (tel.test(value));
    }, '请正确填写用户名');
    // 自定义密码验证
    jQuery.validator.addMethod('isPwd', function (value, element) {
        var tel = /^[a-zA-Z]\w{5,11}$/;
        return this.optional(element) || (tel.test(value));
    }, '请正确填写用密码');
    // 自定义电话号码验证
    jQuery.validator.addMethod('isPhone', function (value, element) {
        var tel = /^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/;
        return this.optional(element) || (tel.test(value));
    }, '请正确填写手机号');
})